import multiprocessing, os, time, random


def worker(index):
    start_time = time.time()
    time.sleep(random.random())
    end_time = time.time()
    print("任务%d  执行时间%.2f  当前进程id是%d" % (index, end_time - start_time, os.getpid()))
    print("当前时间%s    进程的父进程id是%d    进程是否为守护进程： %s" % \
          (time.ctime(), os.getppid(), multiprocessing.current_process().daemon))


if __name__ == "__main__":
    print("main 当前进程的id是%d" % os.getpid())

    pool = multiprocessing.Pool(processes=3)
    for i in range(10):
        pool.apply_async(func=worker, args=(i,))
    pool.close()
    pool.join()
    print("主进程最后执行的代码")
